<template>
  <div id="management" v-loading="showLoading">
    <cus-Breadcrumb level1="用户与权限" level2="角色权限配置" class="mb20"></cus-Breadcrumb>
    <el-card class="cardBox">
      <el-button type="primary" @click="addNewrole()" v-if="!AddFlag && yhlsAdd">新增角色</el-button>
      <el-tag class="tips" v-if="!AddFlag && yhlsAdd">点击新增角色➟输入角色名称➟然后添加权限➟点击提交新增角色</el-tag>
      <el-button type="primary" v-if="AddFlag" class="mt10" @click="commitAdd(false,true)">点击提交</el-button>
      <el-button type="primary" v-if="AddFlag" class="mt10" @click="clickAddRole">点击添加权限</el-button>
      <el-button type="primary" @click="addNewrole" v-if="AddFlag">取消添加</el-button>
      <el-input
        v-model="Name"
        placeholder="请输入角色名称"
        v-if="AddFlag"
        class="roleName"
        :disabled="!treeFlag2"
      ></el-input>
       <el-dialog title="权限树" :visible.sync="treeFlag" class="dialogAdd">
        <el-tree
          default-expand-all
          lazy
          :load="loadChild"
          :data="data2"
          show-checkbox
          node-key="id"
          ref="tree"
          highlight-current
          class="treeStyle"
          v-if="treeFlag && AddFlag"
        ></el-tree>
        <el-button type="primary" class="commitChange" @click="getChecked">确定</el-button>
      </el-dialog>
      <el-table class="mt20" :data="tableData">
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="角色名" width="180" prop="roleName"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope);handleEditRoleList(scope)">查询和编辑</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-dialog title="权限树" :visible.sync="addNewinf" class="dialogAdd">
        <el-tree
          default-expand-all
          :data="data3"
          node-key="id"
          ref="tree2"
          highlight-current
          class="treeStyle"
        ></el-tree>
      </el-dialog>
      <el-dialog title="修改角色" :visible.sync="editFlag" class="dialogAdd" @close="closed">
        <el-tree
          lazy
          :load="loadChild2"
          show-checkbox
          default-expand-all
          :data="data4"
          node-key="id"
          ref="tree3"
          highlight-current
          class="treeStyle"
          :default-checked-keys="defaultArr"
          v-if="hackReset"
        ></el-tree>
        <el-button type="primary" class="commitChange" @click="commitChang()" v-if="yhjsEditSearchCommit">提交更改</el-button>
      </el-dialog>
    </el-card>
  </div>
</template>
<script>
import $$ from '@/plugins/statusCode.config'
export default {
  data () {
    return {
      yhlsAdd: false,
      yhlsEditSearch: false,
      yhjsEditSearchCommit: false,
      yhjsDelete: false,
      treeFlag2: false,
      flag: true,
      keys: [],
      showLoading: false,
      IdArray: [],
      editFlag: false,
      data3: [],
      data4: [],
      addNewinf: false,
      tableData: [],
      Name: '',
      AddFlag: false,
      treeFlag: false,
      // 权限数据
      data2: [],
      changeArr: [],
      checked: '',
      defaultArr: [],
      hackReset: true
    }
  },
  created () {
  },
  mounted () {
    this.showLoading = true
    this.getRole()
    this.role()
  },
  methods: {
    closed () {
      this.$router.push({name: 'role2'})
    },
    role () {
      let arr = JSON.parse(sessionStorage.getItem('buttonRole'))
      for (let i = 0; i < arr.length; i++) {
        if (arr[i] === 'yhjs-add') {
          this.yhlsAdd = true
        }
        if (arr[i] === 'yhjs-editSearch') {
          this.yhlsEditSearch = true
        }
        if (arr[i] === 'yhjs-editSearch-commit') {
          this.yhjsEditSearchCommit = true
        }
        if (arr[i] === 'yhjs-delete') {
          this.yhjsDelete = true
        }
      }
    },
    getChecked () {
      this.treeFlag = false
      this.treeFlag2 = true
      this.checked = this.$refs.tree.getCheckedNodes(false, true)
    },
    // 删除角色 完成token更新
    async handleDelete (scope) {
      const scopes = scope
      const that = this
      const id = scopes.row.id
      let param = new URLSearchParams()
      param.append('id', id)
      this.showLoading = true
      await this.$http8080
        .post('/authorization-operate/removeRole', param)
        .then(function (res) {
          if (res.data.statusCode === $$.s70003) {
            const id = sessionStorage.getItem('id')
            let param = new URLSearchParams()
            param.append('id', id)
            const _that = that
            return that.$refresh
              .post(`/manager-search/updateToken`, param)
              .then(function (res) {
                if (res.data.statusCode === $$.s70005) {
                  sessionStorage.setItem(
                    'accessToken',
                    res.data.data.accessToken
                  )
                  sessionStorage.setItem(
                    'refreshToken',
                    res.data.data.refreshToken
                  )
                  _that.handleDelete(scopes)
                }
              })
          }
          if (res.data.statusCode === $$.s20004) {
            that.showLoading = false
            that.$message.success('删除成功', that.getRole())
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    },
    addNewrole () {
      this.AddFlag = !this.AddFlag
    },
    // 权限树列表 完成token
    async commitAdd () {
      const that = this
      const checked = this.checked
      let arr = []
      for (var i = 0; i < checked.length; i++) {
        arr.push(checked[i].id)
      }
      const authorizationIds = arr.join(',')
      if (authorizationIds.length !== 0 && this.Name.length !== 0) {
        this.showLoading = true
        let param = new URLSearchParams()
        param.append('authorizationIds', authorizationIds)
        param.append('roleName', this.Name)
        await this.$http8080
          .post('/authorization-operate/saveRole', param)
          .then(function (res) {
            if (res.data.statusCode === $$.s70003) {
              const id = sessionStorage.getItem('id')
              let param = new URLSearchParams()
              param.append('id', id)
              const _that = that
              return that.$refresh
                .post(`/manager-search/updateToken`, param)
                .then(function (res) {
                  if (res.data.statusCode === $$.s70005) {
                    sessionStorage.setItem(
                      'accessToken',
                      res.data.data.accessToken
                    )
                    sessionStorage.setItem(
                      'refreshToken',
                      res.data.data.refreshToken
                    )
                    _that.commitAdd()
                  }
                })
            }
            if (res.data.statusCode === $$.s20000) {
              that.showLoading = false
              that.$message.success(res.data.statusMsg)
              that.getRole()
            } else {
              that.showLoading = false
              that.$message.error(res.data.statusMsg)
            }
          })
      } else {
        this.$message.error('请检查是否填写完整')
      }
    },
    // 获取权限列表 完成token
    // authorization-search/flipListAuthorizationByParentId
    async getRole () {
      this.showLoading = true
      const that = this
      await this.$http8081
        .post('/authorization-search/flipListForRole')
        .then(function (res) {
          if (res.data.statusCode === $$.s70003) {
            const id = sessionStorage.getItem('id')
            let param = new URLSearchParams()
            param.append('id', id)
            const _that = that
            return that.$refresh
              .post(`/manager-search/updateToken`, param)
              .then(function (res) {
                if (res.data.statusCode === $$.s70005) {
                  sessionStorage.setItem(
                    'accessToken',
                    res.data.data.accessToken
                  )
                  sessionStorage.setItem(
                    'refreshToken',
                    res.data.data.refreshToken
                  )
                  _that.getRole()
                }
              })
          }
          if (res.data.statusCode === $$.s20006) {
            that.showLoading = false
            that.tableData = res.data.data.records
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    },
    // 权限树列表结束
    // 查询状态树 完成token
    async clickAddRole (node) {
      const nodes = node
      this.treeFlag = !this.treeFlag
      const that = this
      // 发送AJAX请求
      await this.$http8081
        .post('/authorization-search/flipListAuthorizationByParentId')
        .then(function (res) {
          if (res.data.statusCode === $$.s70003) {
            const id = sessionStorage.getItem('id')
            let param = new URLSearchParams()
            param.append('id', id)
            const _that = that
            return that.$refresh
              .post(`/manager-search/updateToken`, param)
              .then(function (res) {
                if (res.data.statusCode === $$.s70005) {
                  sessionStorage.setItem(
                    'accessToken',
                    res.data.data.accessToken
                  )
                  sessionStorage.setItem(
                    'refreshToken',
                    res.data.data.refreshToken
                  )
                  _that.clickAddRole(nodes)
                }
              })
          }
          if (res.data.statusCode === $$.s20006) {
            that.showLoading = false
            const data = res.data.data
            for (var i = 0; i < data.length; i++) {
              let roleObj = {
                id: data[i].id,
                label: data[i].keyName,
                code: data[i].code,
                parentId: data[i].parentId,
                alias: data[i].alias
              }
              if (that.data2.length === 0) {
                that.data2.push(roleObj)
              } else {
                for (var j = 0; j < that.data2.length; j++) {
                  if (
                    !(JSON.stringify(that.data2[i]) === JSON.stringify(roleObj))
                  ) {
                    that.data2.push(roleObj)
                  }
                }
              }
            }
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    },
    // 点击父节点后渲染子节点 完成token
    async loadChild (node, solve) {
      const that = this
      const nodes = node
      const solves = solve
      var theChildren = nodes.childNodes
      theChildren.splice(0, theChildren.length)
      if (nodes.level === 1) {
        let param = new URLSearchParams()
        // param.append('code', nodes.data.code)
        param.append('parentId', nodes.data.id)
        await this.$http8081
          .post('/authorization-search/flipListAuthorizationByParentId', param)
          .then(function (res) {
            if (res.data.statusCode === $$.s70003) {
              const id = sessionStorage.getItem('id')
              let param = new URLSearchParams()
              param.append('id', id)
              const _that = that
              return that.$refresh
                .post(`/manager-search/updateToken`, param)
                .then(function (res) {
                  if (res.data.statusCode === $$.s70005) {
                    sessionStorage.setItem(
                      'accessToken',
                      res.data.data.accessToken
                    )
                    sessionStorage.setItem(
                      'refreshToken',
                      res.data.data.refreshToken
                    )
                    _that.loadChild(nodes, solves)
                  }
                })
            }
            if (res.data.statusCode === $$.s20006) {
              let children = []
              if (res.data.data.length !== 0) {
                for (var i = 0; i < res.data.data.length; i++) {
                  let childrens = {
                    id: res.data.data[i].id,
                    label: res.data.data[i].keyName,
                    code: res.data.data[i].code,
                    parentId: res.data.data[i].parentId
                  }
                  if (children.length === 0) {
                    children.push(childrens)
                  } else {
                    for (var j = 0; j < children.length; j++) {
                      if (
                        !(
                          JSON.stringify(children[i]) ===
                          JSON.stringify(childrens)
                        )
                      ) {
                        children.push(childrens)
                      }
                    }
                  }
                  solve(children)
                }
              } else {
                solve([])
              }
            } else {
              that.$message.error(res.data.statusMsg)
            }
          })
      } else if (nodes.level === 2) {
        let param = new URLSearchParams()
        // param.append('code', nodes.data.code)
        param.append('parentId', nodes.data.id)
        await this.$http8081
          .post('/authorization-search/flipListAuthorizationByParentId', param)
          .then(function (res) {
            if (res.data.statusCode === $$.s70003) {
              const id = sessionStorage.getItem('id')
              let param = new URLSearchParams()
              param.append('id', id)
              const _that = that
              return that.$refresh
                .post(`/manager-search/updateToken`, param)
                .then(function (res) {
                  if (res.data.statusCode === $$.s70005) {
                    sessionStorage.setItem(
                      'accessToken',
                      res.data.data.accessToken
                    )
                    sessionStorage.setItem(
                      'refreshToken',
                      res.data.data.refreshToken
                    )
                    _that.loadChild(nodes, solves)
                  }
                })
            }
            if (res.data.statusCode === $$.s20006) {
              let children = []
              if (res.data.data.length !== 0) {
                for (var i = 0; i < res.data.data.length; i++) {
                  let childrens = {
                    id: res.data.data[i].id,
                    label: res.data.data[i].keyName,
                    code: res.data.data[i].code,
                    parentId: res.data.data[i].parentId
                  }
                  if (children.length === 0) {
                    children.push(childrens)
                  } else {
                    for (var j = 0; j < children.length; j++) {
                      if (
                        !(
                          JSON.stringify(children[i]) ===
                          JSON.stringify(childrens)
                        )
                      ) {
                        children.push(childrens)
                      }
                    }
                  }
                  solve(children)
                }
              } else {
                solve([])
              }
            } else {
              that.$message.error(res.data.statusMsg)
            }
          })
      } else if (nodes.level === 3) {
        let param = new URLSearchParams()
        // param.append('code', nodes.data.code)
        param.append('parentId', nodes.data.id)
        await this.$http8081
          .post('/authorization-search/flipListAuthorizationByParentId', param)
          .then(function (res) {
            if (res.data.statusCode === $$.s70003) {
              const id = sessionStorage.getItem('id')
              let param = new URLSearchParams()
              param.append('id', id)
              const _that = that
              return that.$refresh
                .post(`/manager-search/updateToken`, param)
                .then(function (res) {
                  if (res.data.statusCode === $$.s70005) {
                    sessionStorage.setItem(
                      'accessToken',
                      res.data.data.accessToken
                    )
                    sessionStorage.setItem(
                      'refreshToken',
                      res.data.data.refreshToken
                    )
                    _that.loadChild(nodes, solves)
                  }
                })
            }
            if (res.data.statusCode === $$.s20006) {
              let children = []
              if (res.data.data.length !== 0) {
                for (var i = 0; i < res.data.data.length; i++) {
                  let childrens = {
                    id: res.data.data[i].id,
                    label: res.data.data[i].keyName,
                    code: res.data.data[i].code,
                    parentId: res.data.data[i].parentId
                  }
                  if (children.length === 0) {
                    children.push(childrens)
                  } else {
                    for (var j = 0; j < children.length; j++) {
                      if (
                        !(
                          JSON.stringify(children[i]) ===
                          JSON.stringify(childrens)
                        )
                      ) {
                        children.push(childrens)
                      }
                    }
                  }
                  solve(children)
                }
              } else {
                solve([])
              }
            } else {
              that.$message.error(res.data.statusMsg)
            }
          })
      } else {
        solve([])
      }
    },
    // diago
    // 查询角色对应的权限列表 完成token
    async handleView (scope) {
      this.showLoading = true
      const scopes = scope
      this.addNewinf = true
      const that = this
      const roleId = scopes.row.id
      let param = new URLSearchParams()
      param.append('roleId', roleId)
      await this.$http8081
        .post('/authorization-search/flipListAuthorizationByRoleId', param)
        .then(function (res) {
          if (res.data.statusCode === $$.s70003) {
            const id = sessionStorage.getItem('id')
            let param = new URLSearchParams()
            param.append('id', id)
            const _that = that
            return that.$refresh
              .post(`/manager-search/updateToken`, param)
              .then(function (res) {
                if (res.data.statusCode === $$.s70005) {
                  sessionStorage.setItem(
                    'accessToken',
                    res.data.data.accessToken
                  )
                  sessionStorage.setItem(
                    'refreshToken',
                    res.data.data.refreshToken
                  )
                  _that.handleView(scopes)
                }
              })
          }
          if (res.data.statusCode === $$.s20006) {
            that.showLoading = false
            const data = res.data.data
            that.data3 = []
            for (var i = 0; i < data.length; i++) {
              if (data[i].code.length === 3) {
                let roleObj = {
                  id: data[i].id,
                  label: data[i].keyName,
                  code: data[i].code,
                  parentId: null,
                  alias: data[i].alias
                }
                // const FatherNode = []
                // FatherNode.push(roleObj)
                that.data3.push(roleObj)
              }
              if (data[i].code.length === 6) {
                let childObj = {
                  id: data[i].id,
                  label: data[i].keyName,
                  code: data[i].code,
                  parentId: data[i].parentId,
                  alias: data[i].alias
                }
                for (var j = 0; j < that.data3.length; j++) {
                  if (that.data3[j].code === childObj.code.substring(0, 3)) {
                    that.data3[j].children = []
                    that.data3[j].children.push(childObj)
                  }
                }
              }
            }
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    },
    // 编辑角色
    // 查询当前角色具有哪些权限 完成token
    async handleEditRoleList (scope) {
      this.hackReset = true
      this.nodeKey = ''
      this.defaultArr = []
      this.showLoading = true
      const scopes = scope
      this.changeArr.id = scopes.row.id
      this.changeArr.roleName = scopes.row.roleName
      const that = this
      const roleId = scopes.row.id
      let param = new URLSearchParams()
      param.append('roleId', roleId)
      await this.$http8081
        .post('/authorization-search/flipListAuthorizationByRoleId', param)
        .then(function (res) {
          if (res.data.statusCode === $$.s70003) {
            const id = sessionStorage.getItem('id')
            let param = new URLSearchParams()
            param.append('id', id)
            const _that = that
            return that.$refresh
              .post(`/manager-search/updateToken`, param)
              .then(function (res) {
                if (res.data.statusCode === $$.s70005) {
                  sessionStorage.setItem(
                    'accessToken',
                    res.data.data.accessToken
                  )
                  sessionStorage.setItem(
                    'refreshToken',
                    res.data.data.refreshToken
                  )
                  _that.handleEditRoleList(scopes)
                }
              })
          }
          if (res.data.statusCode === $$.s20006) {
            that.showLoading = false
            const data = res.data.data
            for (let i = 0; i < data.length; i++) {
              // let roleObj = {
              //   id: data[i].id
              // }
              // codeArr.push(roleObj)
              that.defaultArr.push(data[i].id)
            }
            // const sw = codeArr
            // that.$refs.tree3.setCheckedNodes(sw)
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    },
    // 查询所有的权限 完成toekn
    async loadChild2 (node, solve) {
      const that = this
      const nodes = node
      const solves = solve
      var theChildren = nodes.childNodes
      theChildren.splice(0, theChildren.length)
      if (nodes.level === 1) {
        let param = new URLSearchParams()
        // param.append('code', nodes.data.code)
        param.append('parentId', nodes.data.id)
        await this.$http8081
          .post('/authorization-search/flipListAuthorizationByParentId', param)
          .then(function (res) {
            if (res.data.statusCode === $$.s70003) {
              const id = sessionStorage.getItem('id')
              let param = new URLSearchParams()
              param.append('id', id)
              const _that = that
              return that.$refresh
                .post(`/manager-search/updateToken`, param)
                .then(function (res) {
                  if (res.data.statusCode === $$.s70005) {
                    sessionStorage.setItem(
                      'accessToken',
                      res.data.data.accessToken
                    )
                    sessionStorage.setItem(
                      'refreshToken',
                      res.data.data.refreshToken
                    )
                    _that.loadChild2(nodes, solves)
                  }
                })
            } if (res.data.statusCode === $$.s20006) {
              let children = []
              if (res.data.data.length !== 0) {
                for (var i = 0; i < res.data.data.length; i++) {
                  let childrens = {
                    id: res.data.data[i].id,
                    label: res.data.data[i].keyName,
                    code: res.data.data[i].code,
                    parentId: res.data.data[i].parentId,
                    alias: res.data.data[i].alias
                  }
                  if (children.length === 0) {
                    children.push(childrens)
                  } else {
                    for (var j = 0; j < children.length; j++) {
                      if (
                        !(
                          JSON.stringify(children[i]) ===
                          JSON.stringify(childrens)
                        )
                      ) {
                        children.push(childrens)
                      }
                    }
                  }
                  solve(children)
                }
              } else {
                solve([])
              }
            } else {
              that.$message.error(res.data.statusMsg)
            }
          })
      } else if (nodes.level === 2) {
        let param = new URLSearchParams()
        // param.append('code', nodes.data.code)
        param.append('parentId', nodes.data.id)
        await this.$http8081
          .post('/authorization-search/flipListAuthorizationByParentId', param)
          .then(function (res) {
            if (res.data.statusCode === $$.s70003) {
              const id = sessionStorage.getItem('id')
              let param = new URLSearchParams()
              param.append('id', id)
              const _that = that
              return that.$refresh
                .post(`/manager-search/updateToken`, param)
                .then(function (res) {
                  if (res.data.statusCode === $$.s70005) {
                    sessionStorage.setItem(
                      'accessToken',
                      res.data.data.accessToken
                    )
                    sessionStorage.setItem(
                      'refreshToken',
                      res.data.data.refreshToken
                    )
                    _that.loadChild2(nodes, solves)
                  }
                })
            }
            if (res.data.statusCode === $$.s20006) {
              let children = []
              if (res.data.data.length !== 0) {
                for (var i = 0; i < res.data.data.length; i++) {
                  let childrens = {
                    id: res.data.data[i].id,
                    label: res.data.data[i].keyName,
                    code: res.data.data[i].code,
                    parentId: res.data.data[i].parentId,
                    alias: res.data.data[i].alias
                  }
                  if (children.length === 0) {
                    children.push(childrens)
                  } else {
                    for (var j = 0; j < children.length; j++) {
                      if (
                        !(
                          JSON.stringify(children[i]) ===
                          JSON.stringify(childrens)
                        )
                      ) {
                        children.push(childrens)
                      }
                    }
                  }
                  solve(children)
                }
              } else {
                solve([])
              }
            } else {
              that.$message.error(res.data.statusMsg)
            }
          })
      } else if (nodes.level === 3) {
        let param = new URLSearchParams()
        // param.append('code', nodes.data.code)
        param.append('parentId', nodes.data.id)
        await this.$http8081
          .post('/authorization-search/flipListAuthorizationByParentId', param)
          .then(function (res) {
            if (res.data.statusCode === $$.s70003) {
              const id = sessionStorage.getItem('id')
              let param = new URLSearchParams()
              param.append('id', id)
              const _that = that
              return that.$refresh
                .post(`/manager-search/updateToken`, param)
                .then(function (res) {
                  if (res.data.statusCode === $$.s70005) {
                    sessionStorage.setItem(
                      'accessToken',
                      res.data.data.accessToken
                    )
                    sessionStorage.setItem(
                      'refreshToken',
                      res.data.data.refreshToken
                    )
                    _that.loadChild2(nodes, solves)
                  }
                })
            }
            if (res.data.statusCode === $$.s20006) {
              let children = []
              if (res.data.data.length !== 0) {
                for (var i = 0; i < res.data.data.length; i++) {
                  let childrens = {
                    id: res.data.data[i].id,
                    label: res.data.data[i].keyName,
                    code: res.data.data[i].code,
                    parentId: res.data.data[i].parentId,
                    alias: res.data.data[i].alias
                  }
                  if (children.length === 0) {
                    children.push(childrens)
                  } else {
                    for (var j = 0; j < children.length; j++) {
                      if (
                        !(
                          JSON.stringify(children[i]) ===
                          JSON.stringify(childrens)
                        )
                      ) {
                        children.push(childrens)
                      }
                    }
                  }
                  solve(children)
                }
              } else {
                solve([])
              }
            } else {
              that.$message.error(res.data.statusMsg)
            }
          })
      } else {
        solve([])
      }
    },
    async handleEdit (scope) {
      this.showLoading = true
      const scopes = scope
      this.editFlag = true
      const that = this
      // 发送AJAX请求
      await this.$http8081
        .post('/authorization-search/flipListAuthorizationByParentId')
        .then(function (res) {
          if (res.data.statusCode === $$.s70003) {
            const id = sessionStorage.getItem('id')
            let param = new URLSearchParams()
            param.append('id', id)
            const _that = that
            return that.$refresh
              .post(`/manager-search/updateToken`, param)
              .then(function (res) {
                if (res.data.statusCode === $$.s70005) {
                  sessionStorage.setItem(
                    'accessToken',
                    res.data.data.accessToken
                  )
                  sessionStorage.setItem(
                    'refreshToken',
                    res.data.data.refreshToken
                  )
                  _that.handleEdit(scopes)
                }
              })
          }
          if (res.data.statusCode === $$.s20006) {
            that.showLoading = false
            const data = res.data.data
            for (var i = 0; i < data.length; i++) {
              let roleObj = {
                id: data[i].id,
                label: data[i].keyName,
                code: data[i].code,
                parentId: data[i].parentId,
                alias: data[i].alias
              }
              if (that.data4.length === 0) {
                that.data4.push(roleObj)
              } else {
                for (var j = 0; j < that.data4.length; j++) {
                  if (
                    !(JSON.stringify(that.data4[i]) === JSON.stringify(roleObj))
                  ) {
                    that.data4.push(roleObj)
                  }
                }
              }
            }
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    },
    async commitChang () {
      this.showLoading = true
      const that = this
      const checked = this.$refs.tree3.getCheckedNodes(false, true)
      const arr = []
      for (var i = 0; i < checked.length; i++) {
        arr.push(checked[i].id)
      }
      this.changeArr.authorizationIds = arr.join(',')
      let param = new URLSearchParams()
      param.append('authorizationIds', this.changeArr.authorizationIds)
      param.append('roleName', this.changeArr.roleName)
      param.append('id', this.changeArr.id)
      await that.$http8080
        .post('/authorization-operate/editRole', param)
        .then(function (res) {
          if (res.data.statusCode === $$.s70003) {
            const id = sessionStorage.getItem('id')
            let param = new URLSearchParams()
            param.append('id', id)
            return that.$refresh
              .post(`/manager-search/updateToken`, param)
              .then(function (res) {
                if (res.data.statusCode === $$.s70005) {
                  sessionStorage.setItem(
                    'accessToken',
                    res.data.data.accessToken
                  )
                  sessionStorage.setItem(
                    'refreshToken',
                    res.data.data.refreshToken
                  )
                  // _that.handleEdit(scopes)
                }
              })
          } else if (res.data.statusCode === $$.s20002) {
            that.showLoading = false
            that.editFlag = false
            that.$message.success('修改成功')
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    }
  }
}
</script>
<style scope="scoped">
.roleName {
  display: block;
  margin-top: 10px;
  width: 20%;
}
.cardBox {
  height: 850px;
}
.mt10 {
  margin-top: 10px;
}
.treeStyle {
  width: 300px;
  display: block;
}
.el-dialog {
  min-height: 300px;
}
.commitChange {
  position: absolute;
  right: 30px;
  bottom: 50px;
}
.tips {
  position: absolute;
  top: 170px;
  left: 800px;
}
</style>
